import axios from 'axios'


const request = axios.create({ timeout: 10000 })


request.interceptors.request.use((config) => {
	config.headers!['token'] = JSON.stringify(localStorage.getItem('token'))
	return config
}, (error) => {
	return Promise.reject(error)
})

request.interceptors.response.use((response) => {
	const { code } = response.data;
	switch (code) {
		case 200:
			console.log('OK');
			break

		case 400:
			console.log('客户端错误');
			break
		case 500:
		case 501:
		case 502:
		case 503:
			console.log('服务器错误');
			break
	}
	return response
}, (error) => {
	return Promise.reject(error)
})


export default request